<template>
	<view>
		<simple-toolbar :title="$t('asset.extract.newExtractTit')">
			<view>
				<el-button @click="navBack">{{ $t('asset.extract.return') }}</el-button>
				<el-button @click="confirm" type="primary" :disabled="success">{{ $t('asset.extract.confirm') }}</el-button>
			</view>
		</simple-toolbar>

		<el-form :model="formData" :rules="rules" ref="formData" label-position="top" class="pad-base">
			<el-form-item :label="$t('wallet.editWallet.coin')" prop="coin">
				<el-select v-model="formData.coin" :placeholder="$t('wallet.editWallet.coin_pla')">
					<el-option v-for="item in coinList" :key="item.id" :label="item.coin_name" :value="item.id"></el-option>
				</el-select>
			</el-form-item>
<!-- 			<el-form-item :label="$t('asset.extract.amount')" prop="amount">
				<el-input v-model="formData.amount" :placeholder="$t('asset.extract.amount_pla')"></el-input>
			</el-form-item>
			<text class="text">{{ $t('asset.extract.tips') }}</text> -->
		</el-form>
	</view>

	<!-- <view v-else>
		<simple-toolbar title="资产-修改提币申请">
			<view>
				<el-button @click="navBack">返回</el-button>
				<el-button @click="confirm" type="primary" :disabled="success">确认</el-button>
			</view>
		</simple-toolbar>

		<el-form :model="formData" :rules="rules" ref="formData" label-position="top" class="pad-base">
			<el-form-item label="提币号-ID" required>
				<el-input v-model="formData.id" disabled></el-input>
			</el-form-item>
			<el-form-item label="数量" prop="amount" required v-if="state == 1">
				<el-input v-model="formData.amount"></el-input>
			</el-form-item>
			<el-form-item label="状态" prop="status" required v-else>
				<el-select v-model="formData.status" placeholder="请选择">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
		</el-form>
	</view> -->
</template>

<script>
	import {
		applyExtract
	} from "../../../js_sdk/uni-admin/asset.js"
	import {
		getCoinList
	} from "@/js_sdk/uni-admin/wallet.js"
	export default {
		// onLoad(option) {
		// 	this.state = option.state
		// 	if (option.state == 1) return
		// 	this.formData = JSON.parse(decodeURIComponent(option.data))
		// },
		data() {
			return {
				coinList: [],
				success: false,
				options: [{
					value: 'pending',
					label: 'pending'
				}, {
					value: 'cancelle',
					label: 'cancelle'
				}],
				formData: {
					// amount: '',
					coin: ''
				},
				rules: {
					amount: [{
						required: true,
						// message: this.$t('asset.extract.amount_pla'),
						validator: (rule, value, callback) => {
							if (value === '') {
								callback(new Error(this.$t('asset.extract.amount_pla')))
							} else {
								callback()
							}
						},
						trigger: 'blur'
					}],
					status: [{
						required: true,
						// message: this.$t('asset.extract.status_pla'),
						validator: (rule, value, callback) => {
							if (value === '') {
								callback(new Error(this.$t('asset.extract.status_pla')))
							} else {
								callback()
							}
						},
						trigger: 'blur'
					}],
					coin: [{
						required: true,
						validator: (rule, value, callback) => {
							if (value === '') {
								callback(new Error(this.$t('wallet.editWallet.coin_pla')))
							} else {
								callback()
							}
						},
						trigger: 'blur'
					}],
				},
				state: undefined
			}
		},
		onShow() {
			// let data = uni.getStorageSync('coinList')
			// if (data) {
			// 	if (typeof data == 'string') {
			// 		this.coinList = JSON.parse(uni.getStorageSync('coinList'))
			// 	} else {
			// 		this.coinList = data
			// 	}
			// }
			this.loadData()
		},
		methods: {
			async loadData() {
				try{
					let res = await getCoinList()
					this.coinList = res.data
				}catch(e){
					console.error(e)
				}
			},
			confirm() {
				this.$refs.formData.validate(async valid => {
					if (!valid) return
					// let method = ''
					// let data = {}
					// if (this.state == 1) {
					// 	method = 'post'
					// 	data = {
					// 		id: this.formData.id,
					// 		amount: this.formData.amount * 1,
					// 	}
					// } else {
					// 	method = 'put'
					// 	data = {
					// 		id: this.formData.id,
					// 		status: this.formData.status
					// 	}
					// }
					// await applyExtract(method, data)
					await applyExtract('post', this.formData)
					this.success = true
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				})
			},
			navBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style>
	.text {
		font-size: 5.46rpx;
		color: #3B3E66;
	}
	/deep/ .el-select {
		width: 100%;
	}
</style>
